# -*- coding: utf-8 -*-
import sys
import os
import socket

# 导入日志
from center import LOGGING

# 添加path
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
BASE_DIR = os.path.dirname(PROJECT_ROOT)

if PROJECT_ROOT not in sys.path:
    sys.path.insert(0, PROJECT_ROOT)
if os.path.dirname(BASE_DIR) not in sys.path:
    sys.path.insert(0, os.path.dirname(BASE_DIR))

import public_settings

DEBUG = public_settings.debug
AREA = public_settings.area
TIME_ZONE = public_settings.time_zone
GM_ROUTE = public_settings.gm_route
NOTICE_OPEN = public_settings.notice_open

TITLE = public_settings.title
account_prefix = public_settings.prefix

# des加密配置
Des_Key = "youai123"
Des_IV = "12345678"

LOG_DB_PASSWORD = "hskz@gk2020"

TEMPLATE_DEBUG = DEBUG
ALLOWED_HOSTS = '*'
INTERNAL_IPS = ('127.0.0.1',)
SITE_ID = 1
LANGUAGE_CODE = 'zh-hans'
DEFAULT_CHARSET = 'utf-8'
USE_I18N = True
USE_L10N = True
CACHE_MIDDLEWARE_SECONDS = 3600
SECRET_KEY = 'f7r5a)rf1j99le=$jnq2rq&o1yoezuq#q9#2r)s^pz1i-6eja-'

ROOT_URLCONF = 'center.urls'
WSGI_APPLICATION = 'django_wsgi.application'

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'HOST': public_settings.mysql_host,
        'PORT': public_settings.mysql_port,
        'NAME': public_settings.center_name,
        'USER': public_settings.mysql_user,
        'PASSWORD': public_settings.mysql_passwd,
    },
    'read': {
        'ENGINE': 'django.db.backends.mysql',
        'HOST': public_settings.mysql_host,
        'PORT': public_settings.mysql_port,
        'NAME': public_settings.center_name,
        'USER': public_settings.mysql_user,
        'PASSWORD': public_settings.mysql_passwd,
    },
    'write': {
        'ENGINE': 'django.db.backends.mysql',
        'HOST': public_settings.mysql_host,
        'PORT': public_settings.mysql_port,
        'NAME': public_settings.center_name,
        'USER': public_settings.mysql_user,
        'PASSWORD': public_settings.mysql_passwd,
    },
    # 'card': {
    #     'ENGINE': 'django.db.backends.mysql',
    #     'HOST': public_settings.mysql_host,
    #     'PORT': public_settings.mysql_port,
    #     'NAME': public_settings.card_name,
    #     'USER': public_settings.mysql_user,
    #     'PASSWORD': public_settings.mysql_passwd,
    # },
    # 'pay': {
    #     'ENGINE': 'django.db.backends.mysql',
    #     'HOST': public_settings.mysql_host,
    #     'PORT': public_settings.mysql_port,
    #     'NAME': public_settings.pay_name,
    #     'USER': public_settings.mysql_user,
    #     'PASSWORD': public_settings.mysql_passwd,
    # },
    # 'statistic': {
    #     'ENGINE': 'django.db.backends.mysql',
    #     'HOST': public_settings.mysql_host,
    #     'PORT': public_settings.mysql_port,
    #     'NAME': public_settings.statistic_name,
    #     'USER': public_settings.mysql_user,
    #     'PASSWORD': public_settings.mysql_passwd,
    #     },
}
#
REDIS = {
    # 'HOST': public_settings.redis_host,
    # 'PORT': public_settings.redis_port,
    # 'PASSWORD': public_settings.redis_pass,
    # 0库1库2库默认用于异步和异步任务的缓存，3库充值相关缓存，4库用于api(数据上报)
}

CACHES = {
    'open': False,  # 开启缓存时必须用redis缓存
    # "default": {
    # "BACKEND": "django_redis.cache.RedisCache",
    # "LOCATION": "redis://%s:%s/2" % (public_settings.redis_host, public_settings.redis_port),
    # "OPTIONS": {
    #     "CLIENT_CLASS": "django_redis.client.DefaultClient",
    #     "PASSWORD": public_settings.redis_pass
    # }
    # }
    'default': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': '127.0.0.1:11211',
    }
}

# 获取文件路径示例
# server_path = os.path.join(STATIC_ROOT, 'server')
# server_file = os.path.join(os.path.join(STATIC_ROOT, 'server'), 'all.json')
STATIC_URL = '/static/'
MEDIA_ROOT = os.path.join(os.path.dirname(PROJECT_ROOT), 'static')
STATIC_ROOT = os.path.join(os.path.dirname(os.path.dirname(PROJECT_ROOT)), 'static')

STATICFILES_DIRS = [
    os.path.join(os.path.dirname(PROJECT_ROOT), 'static')
]

TEMPLATE_DIRS = (
    os.path.join(os.path.dirname(PROJECT_ROOT), 'templates'),
)

MIDDLEWARE = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'center.middleware.CustomRequestMiddleware',
    'center.middleware.AuthMiddleware',
)

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',  # 定义模版引擎
        'DIRS': [os.path.join(os.path.dirname(PROJECT_ROOT), 'templates'), ],
        'APP_DIRS': True,  # 是否在APP里查找模版
        'OPTIONS': {  # 用户填充在 RequestContext 上下文的调用函数选项，一般不需要修改
            'context_processors': [  # 上下文处理列表
                'django.template.context_processors.debug',  # 调试
                'django.template.context_processors.request',  # 请求
                'django.contrib.auth.context_processors.auth',  # 认证
                'django.contrib.messages.context_processors.messages',  # 消息
            ],
        },
    },
]

INSTALLED_APPS = [
    'django.contrib.sessions',
    'django.contrib.staticfiles',
    'package.apps.PackageConfig',
    # 'authority.apps.AuthorityConfig',
    # 'operation.apps.OperationConfig',
    # 'scripts.apps.ScriptsConfig',
    'public_util.apps.PublicUtilConfig',
]

DEBUG_TOOLBAR_PANELS = (
    'debug_toolbar.panels.version.VersionDebugPanel',
    'debug_toolbar.panels.timer.TimerDebugPanel',
    'debug_toolbar.panels.settings_vars.SettingsVarsDebugPanel',
    'debug_toolbar.panels.headers.HeaderDebugPanel',
    'debug_toolbar.panels.request_vars.RequestVarsDebugPanel',
    'debug_toolbar.panels.template.TemplateDebugPanel',
    'debug_toolbar.panels.sql.SQLDebugPanel',
    'debug_toolbar.panels.signals.SignalDebugPanel',
    'debug_toolbar.panels.logger.LoggingPanel',
)

print('=' * 40, os.getpid())
print('The environment is %s !' % socket.gethostname())